#include "ecb/benchmarks/mpb/PeakFunctionHilly.h"

#include "ecb/base/Math.h"
#include <math.h>

namespace ecb {

    namespace mpb {

        PeakFunctionHilly::PeakFunctionHilly() { }

        PeakFunctionHilly::~PeakFunctionHilly() { }

        scalar PeakFunctionHilly::f(const std::vector<scalar>& x, const Matrix2D& peaks, int peakIndex) {
            double dummy = Math::Pow2(x[0] - peaks[peakIndex][0]);
            for (size_t j = 1; j < x.size(); j++) {
                dummy += Math::Pow2(x[j] - peaks[peakIndex][j]);
            }
            return peaks[peakIndex][x.size() + 1]
                    - (peaks[peakIndex][x.size()] * dummy)
                    - 0.01 * sin(20.0 * dummy);

        }

        std::string PeakFunctionHilly::toString() const{
            return "PeakFunctionHilly";
        }

    }
}
